<?php
include ('chek.php');
//修改管理员账号或密码
$row=array(
    'auser'=>'',
    'apass'=>''
);
$aid=$input->get('aid');
if($aid){
    $sql="select * from admin WHERE aid='{$aid}'";
    $row=$db->query($sql)->fetch_array(MYSQLI_ASSOC);
}
//添加管理员
if($input->get('do')=='chk'){
    $t_user=$input->post('t_user');
    $t_pass=$input->post('t_pass');
    if($t_user=='' || $t_pass==''){
        die('账号或密码不能为空！');
    }
    $sql_j="select * from admin WHERE auser='{$t_user}' AND aid<>'{$aid}'";
    $sql_j_result=$db->query($sql_j)->fetch_array(MYSQLI_ASSOC);
    if(is_array($sql_j_result)){
        die('此账号已存在！');
    }
    if($aid>0){
        $sql="update admin set auser='{$t_user}' , apass='{$t_pass}' WHERE aid='{$aid}'";
    }
    else{
        $sql="insert into admin (`auser`,`apass`) VALUES ('{$t_user}','{$t_pass}')";
    }
    $is=$db->query($sql);
    if($is){
        header('location:blog.php');
    }
    else{
        die(' 执行失败！');
    }
}

?>
<!DOCTYPE HTML>
<html>
<head>
    <title>添加管理</title>
    <meta charset="utf-8"/>
    <?php include ('../headr.php');?>
</head>
<body>
    <?php include ('nav.php');?>
    <div class="container">
        <div class="row">
            <h2>管理员管理<a href="blog.php" class="pull-right btn btn-default">返回</a></h2>
            <hr/>
            <form class="form-horizontal" action="blog_add.php?do=chk&aid=<?php echo $aid;?>" method="post">
                <div class="form-group">
                    <label for="inputEmail3" class="col-sm-2 control-label">用户名</label>
                    <div class="col-sm-6">
                        <input type="text" name="t_user" class="form-control" id="inputEmail3" placeholder="请输入用户名" value="<?php echo $row['auser'];?>">
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
                    <div class="col-sm-6">
                        <input type="password" name="t_pass" class="form-control" id="inputPassword3" placeholder="请输入密码" value="<?php echo $row['apass'];?>">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-6">
                        <button type="submit" class="btn btn-default">添加</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</body>
</html>
